library(rdrobust)
library(foreign)
library(plyr)
library(ggplot2)
library(rdd)


#################
# RD Figure: MAIN EFFECTS - HH LEVEL OUTCOMES
setwd("\\Users\\KKOSEC\\Dropbox (IFPRI)\\Ethio decentralisation\\Replication\\IFPRI_2008_09_Survey\\IFPRI_HH_Level_Survey")

d <- read.table("Figure_6_Coefficients.txt",header=T)
d$pe <- d$c1
d$se <- d$c2
d$lb <- d$pe- 1.96*d$se
d$ub <- d$pe+ 1.96*d$se
d$group <- factor(d$c3,levels=c(10,9,8,7,6,5,4,3,2,1),
                  labels=c("Uses modern inputs","Numer of modern inputs used","Uses fertilizer","Uses insecticide","Uses herbicide","Uses improved seed","Uses improved drinking water - wet season","Uses improved drinking water - dry season","Time to get to water - wet season","Time to get to water - dry season")[10:1])

f1 = ggplot(data = d, aes(x = group, y = pe, width=0.5,ymin = lb, ymax = ub))
f1 = f1 + geom_pointrange(size=0.5, position = position_dodge(width=.5))
f1 = f1 + scale_shape_manual(values=c(22,22))  
f1 = f1 + scale_fill_manual(values=c("black","black"))
f1 = f1 + coord_flip()
f1 = f1 + geom_hline(yintercept=0, linetype="longdash", size=0.5)
f1 = f1 + theme(axis.text=element_text(size=8), axis.title=element_text(size=10,face="bold"))
f1 = f1 + ylab("Effect of Decentralization with 95% C.I.") + xlab("Dependent Variable") 

f1 = f1+ theme(plot.background= element_rect(fill="grey100"),
               panel.background= element_rect(fill="grey100", color= "grey75"),
               panel.grid.major = element_line(color= "grey75"),
               panel.grid.minor = element_line(color= "grey80"),
               panel.grid.major.y = element_blank(),
               panel.grid.minor.y = element_blank(),
               panel.spacing.x = unit(12,"point"),
               axis.text = element_text(lineheight=0.5),
               legend.background = element_rect(fill="grey100")
)
print(f1)

